/*
    Flood is a program to test the cut method on soft constraints problems
    Copyright (C) 2011  Mattia Gamba

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


#ifndef SOLVER_H
#define SOLVER_H

#include "generator.h"

class Solution {
public:
    Solution(){}
    Solution(qint64 t, Parameters p, QVector<int> s, int a, int j, int c):solution(s),pam(p),cpuTime(t),alpha(a),jumps(j), cuts(c){}
    QString getSolutionStr(){
        QString solu = "";
        for(int i = 0; i < solution.size(); i++){
            solu.append(QString().setNum(solution.at(i)));
        }
        solu.append(" cut:");
        solu.append(QString().setNum(alpha));
        return solu;
    }
    float getCpuTime()const{return cpuTime;}
    void setCpuTime(float t){cpuTime = t;}
    Parameters getPam(){return pam;}
    float getJumps()const{return jumps;}
    void setJumps(float j){jumps = j;}
    float getCuts()const{return cuts;}
    void setCuts(float c){cuts = c;}

private:
    QVector<int> solution;
    Parameters pam;
    float cpuTime;
    float alpha;
    float jumps;
    float cuts;
};

class Solver
{
public:
    Solver();
    void setCP(bool cp){checking = cp;}
    bool getCP()const {return checking;}
    Solution solveProblem(Problem *);
    int findMinimum(int, Problem *);
    bool solveHard(Problem *, QVector<int>&);
    void solveWithProp(int, QVector<Variable>, bool&, QVector<int>&);
    void solveNoProp(int, QVector<Variable>, bool&, QVector<int>&);
    void prop(int, int, QVector<Variable>&, bool&);
    bool cons(QVector<int>&, int, int);
private:
    bool checking;
    Problem * pr;
    int jumpz;
    QVector<float> jumps;
};

#endif // SOLVER_H
